package com.lh.web.service.impl.order;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.lh.common.entity.admin.*;
import com.lh.common.utils.PageUtils;
import com.lh.web.dao.admin.OrderAfterSaleMapper;
import com.lh.web.dao.admin.OrderMapper;
import com.lh.web.service.serviceAdmin.order.AfterSalesOrderService;
import com.lh.web.service.serviceAdmin.order.OrderAfterSaleLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author FH
 * @ClassName: AfterSalesOrderServiceImpl
 * @Description: (类作用)
 * @date: 2020-05-19 10:11
 */
@Service
public class AfterSalesOrderServiceImpl extends ServiceImpl<OrderAfterSaleMapper, OrderAfterSale> implements AfterSalesOrderService {

    @Autowired
    OrderAfterSaleLogService orderLogService;

    @Autowired
    OrderMapper orderMapper;

    @Override
    public PageUtils queryAfterSaleOrderList(Map<String, Object> param, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<OrderAfterSaleAdmin> notices = this.baseMapper.queryAfterSaleOrderList(param);
        return new PageUtils(notices);
    }

    @Override
    public OrderAfterSaleAdmin queryAfterSaleOrder(String afterSaleId) {
        return this.baseMapper.queryAfterSaleOrder(afterSaleId);
    }

    @Override
    public int updateAfterSaleOrder(String afterSaleId, Long userId, String oldStatus,String newStatus, String remark) {
        int i = this.baseMapper.updateAfterSaleOrder(afterSaleId, newStatus);
        orderLogService.insertOrderLog(userId,afterSaleId,oldStatus,newStatus,remark);
        return i;
    }

    @Override
    public int updateOperAfterSaleOrder(String afterSaleId, Long userId, Long addrId, Long refuseId, String oldStatus, String newStatus, String remark) {
        int i = this.baseMapper.updateOperAfterSaleOrder(afterSaleId, newStatus,addrId,refuseId,new Date());
        orderLogService.insertOrderLog(userId,afterSaleId,oldStatus,newStatus,remark);
        return i;
    }

    @Override
    public OrderAfterSaleDetails queryAfterSalesDetails(String afterSaleId) {
        OrderAfterSaleDetails orderAfterSaleDetails = this.baseMapper.queryAfterSalesDetails(afterSaleId);
        List<OrderShop> orderShop = orderMapper.queryOrderShop(orderAfterSaleDetails.getOrderItem());
        List<OrderLog> maps = orderLogService.queryAfterSalesLog(afterSaleId);
        orderAfterSaleDetails.setOrderShop(orderShop);
        orderAfterSaleDetails.setOrderLog(maps);
        return orderAfterSaleDetails;
    }
}
